/*
 * AppHandler.java
 *
 * Created on 31 December 2009, 6:37
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package fasea.index.filehandler;

import java.io.File;
import org.apache.commons.io.FilenameUtils;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;

/**
 *
 * @author gvasil
 */
class AppHandler extends FileHandler {

    private static final String APP_FIELD = "app";
    private static final String CONTENT_FIELD = "content";

    
    protected Document getTypedDocument(File file) throws FileHandlerException {
        org.apache.lucene.document.Document doc = createDefaultLuceneDocument(file);
        String fileName = file.getName().toLowerCase();
        String ext = FilenameUtils.getExtension(fileName);
        String name = FilenameUtils.getName(fileName);

        doc.add(new Field(APP_FIELD, name + " " + ext + " " + fileName, Field.Store.NO,
                Field.Index.ANALYZED));

        doc.add(new Field(CONTENT_FIELD, name + " " + ext + " " + fileName, Field.Store.NO,
                Field.Index.ANALYZED, Field.TermVector.WITH_OFFSETS));

        return doc;
    }
}
